[ty] Model int and str enum value normalization#26349
Merged
charliermarsh merged 24 commits intoJun 27, 2026
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
0 | 7 | 0 |
| Total | 0 | 7 | 0 |
Raw diff:
schemathesis (https://github.com/schemathesis/schemathesis)
- src/schemathesis/generation/overrides.py:75:59 error[invalid-argument-type] Argument to function `lookup_parameter` is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/generation/dictionaries.py:112:73 error[invalid-argument-type] Argument to function `_find_parameter_binding` is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/generation/dictionaries.py:115:97 error[invalid-argument-type] Argument to function `_find_parameter_binding` is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/generation/dictionaries.py:230:21 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/specs/openapi/extra_data_source.py:181:9 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/specs/openapi/extra_data_source.py:199:9 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `Literal["query", "header", "path", "cookie", "body"] | None`
- src/schemathesis/specs/openapi/extra_data_source.py:645:38 error[invalid-argument-type] Argument to bound method `list.append` is incorrect: Expected `tuple[str, str]`, found `tuple[Literal["query", "header", "path", "cookie", "body"] | None, str]`
Merging this PR will not alter performance
Comparing Footnotes
|
e443c06 to
99e6ef0
Compare
65f063a to
1599879
Compare
99e6ef0 to
70a659b
Compare
1599879 to
6ce7e33
Compare
70a659b to
579b61b
Compare
579b61b to
193d068
Compare
2f27190 to
532e2cd
Compare
146ef8b to
80c7281
Compare
3fed494 to
a4f16cb
Compare
charliermarsh
added a commit
that referenced
this pull request
Jun 27, 2026
## Summary
When creating an enum class, CPython checks an inherited
`__new_member__` before falling back to an inherited `__new__` or the
data-type constructor. We previously skipped that lookup, so a parent
enum could replace `_value_` while we continued to expose the member's
declared right-hand side as its precise `.value` type.
This change includes inherited `__new_member__` in enum constructor
discovery. When that hook is user-defined, member values now use the
same conservative inference as other custom construction paths:
```python
from enum import Enum
class Base(Enum):
def __new_member__(cls: type["Base"], value: int) -> "Base":
obj = object.__new__(cls)
obj._value_ = str(value)
return obj
class Child(Base):
VALUE = 1
reveal_type(Child.VALUE.value) # Any
```
This is split out from #26349 so constructor discovery can land
independently of built-in enum mixin normalization.
Base automatically changed from
charlie/detect-inherited-enum-new-member
to
main
June 27, 2026 02:45
a4f16cb to
9c736d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For enums that inherit from
intorstr, Python converts each assigned value before storing it.For example:
Python converts
Falseto0. Therefore:Number.FALSE.valueis0, notFalse.Number.ZEROis another name forNumber.FALSE, not a separate member.Previously, we reasoned from the values as written (
Falseand0) and could incorrectly treat them as different members. We now account for the conversion performed byintorstr. And when we can't reliably predict it, we return a less precise type.